package com.dtsz.m2.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.android.volley.Request;
import com.dtsz.m2.R;
import com.dtsz.m2.config.UrlConfig;
import com.dtsz.m2.ui.base.BaseActivity;
import com.dtsz.m2.ui.model.PayOrderVo;
import com.dtsz.m2.utils.StringUtils;
import com.dtsz.m2.volley.state.HUCState;

public class TransferActivity extends BaseActivity {
    private TextView tvName, tvPrice, tvAccountNumber;
    private Button btSave;
    private EditText etName, etCard, etNum, etRemake;
    private PayOrderVo payOrderVo = new PayOrderVo();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_transfer);
        super.onCreate(savedInstanceState);
        tvActionbarTitle.setText("转出");
        Bundle bundle = getIntent().getExtras();
        tvName.setText("姓名：" + bundle.getString("buName"));
        tvAccountNumber.setText(bundle.getString("buAccountNumber"));
        tvPrice.setText("M2币：" + bundle.getString("buSumYes") + "㎡");
        payOrderVo.setToken(pageVo.getToken());
    }

    @Override
    public void initView() {
        super.initView();
        tvName = findViewById(R.id.tv_name);
        tvPrice = findViewById(R.id.tv_price);
        tvAccountNumber = findViewById(R.id.tv_account_number);
        etName = findViewById(R.id.et_name);
        etCard = findViewById(R.id.et_card);
        etNum = findViewById(R.id.et_num);
        etRemake = findViewById(R.id.et_remake);
        btSave = findViewById(R.id.bt_save);
    }

    @Override
    public void initClick() {
        super.initClick();
        btSave.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.bt_save:
                String name = etName.getText().toString();
                if (StringUtils.isEmpty(name)) {
                    showToast("收币人姓名不能为空");
                    return;
                }
                String card = etCard.getText().toString();
                if (StringUtils.isEmpty(card)) {
                    showToast("收币人地址不能为空");
                    return;
                }
                String num = etNum.getText().toString();
                if (StringUtils.isEmpty(num)) {
                    showToast("数量不能为空");
                    return;
                }
                String remake = etRemake.getText().toString();
                if (!StringUtils.isEmpty(remake)) {
                    payOrderVo.setRemake(remake);
                }
                payOrderVo.setName(name);
                payOrderVo.setAddress(card);
                payOrderVo.setCount(num);
                initNetWork();
                break;
        }
    }

    private void initNetWork() {
        loading();
        hucRequestInterfase.executeStr(this, String.class,
                HUCState.HUC_REQEUST_CODE_1, Request.Method.POST, UrlConfig.ADVANCEINWARDTURN_URL,
                hucParameInterfase.getRequestParameter(payOrderVo), true);
    }

    @Override
    public void onSuccessfulStrType(int inputType, Object response) {
        super.onSuccessfulStrType(inputType, response);
        switch (inputType) {
            case HUCState.HUC_REQEUST_CODE_1:
                String str = (String) response;
                if (str.indexOf("M2") != -1) {
                    sendIntent(this, GestureLoginActivity.class, str);
                    finish();
                } else {
                    showToast(str);
                }
                loadDismiss();
                break;
        }
    }
}
